package com.cskaoyan.market.service.admin.impl;

import com.cskaoyan.market.db.domain.MarketGoodsExample;
import com.cskaoyan.market.db.domain.MarketGoodsProductExample;
import com.cskaoyan.market.db.domain.MarketOrderExample;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketGoodsMapper;
import com.cskaoyan.market.db.mapper.MarketGoodsProductMapper;
import com.cskaoyan.market.db.mapper.MarketOrderMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.service.admin.MarketDashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @MethodName MarketAdminDashboardServiceImpl
 * @Description  分别获取Dashboard中的数据总数
 * @Author M
 * @Date 10:49 2023/5/6
 **/
@Service
public class MarketDashboardServiceImpl implements MarketDashboardService {

    @Autowired
    MarketGoodsMapper goodsMapper;
    @Autowired
    MarketUserMapper userMapper;
    @Autowired
    MarketGoodsProductMapper goodsProductMapper;
    @Autowired
    MarketOrderMapper marketOrderMapper;

    // 商品数量
    @Override
    public int getGoodsTotal() {


        MarketGoodsExample marketGoodsExample = new MarketGoodsExample();
        marketGoodsExample.or().andDeletedEqualTo(false);

        long goodsTotal = goodsMapper.countByExample(marketGoodsExample);

        return (int) goodsTotal;
    }

    @Override
    public int getUserTotal() {

        MarketUserExample marketUserExample = new MarketUserExample();
        marketUserExample.or().andDeletedEqualTo(false);
        long userTotal = userMapper.countByExample(marketUserExample);

        return (int) userTotal;
    }

    @Override
    public int getProductTotal() {

        MarketGoodsProductExample marketGoodsProductExample = new MarketGoodsProductExample();
        marketGoodsProductExample.or().andDeletedEqualTo(false);
        long productTotal = goodsProductMapper.countByExample(marketGoodsProductExample);

        return (int) productTotal;
    }

    @Override
    public int getOrderTotal() {

        MarketOrderExample marketOrderExample = new MarketOrderExample();
        marketOrderExample.or().andDeletedEqualTo(false);
        long orderTotal = marketOrderMapper.countByExample(marketOrderExample);

        return (int) orderTotal;
    }
}
